/**
 *
 * 版权所有 © cybersky.com
 *
 */
package cn.cybertron.primus.report.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Table;

import cn.cybertron.nutz.ext.mvc.validate.ValidateRuleType;
import cn.cybertron.nutz.ext.mvc.validate.annotation.ValidateType;
import cn.cybertron.nutz.ext.mvc.validate.annotation.Validations;
import cn.cybertron.primus.report.query.ReportQuery;

/**
 * 报表类
 * @author: ch
 */
@Table("report_object")
public class ReportObject extends ReportBase implements Serializable {

	private static final long serialVersionUID = -3169196374740148675L;

	/**
	 * 中间表ID：通过sql 生成报表时不需中间表
	@Validations(rules = {
		@ValidateType(type = ValidateRuleType.required, msgkey = "report.validate.cacheid.required", bundle = "report")
	})
	 */
	@Column
	protected String cacheid;

	/**
	 * 主标题
	 */
	@Column
	@Validations(rules = {
		@ValidateType(type = ValidateRuleType.required, msgkey = "report.validate.title.required", bundle = "report"),
		@ValidateType(type = ValidateRuleType.maxlength, parameters = {	"64" }, msgkey = "report.validate.title.maxLength", bundle = "report")
	})
	protected String title;
	
	/**
	 * 副标题
	 */
	@Column
	@Validations(rules = {
		@ValidateType(type = ValidateRuleType.required, msgkey = "report.validate.subtitle.required", bundle = "report"),
		@ValidateType(type = ValidateRuleType.maxlength, parameters = {	"64" }, msgkey = "report.validate.subtitle.maxLength", bundle = "report")
	})
	protected String subtitle;

	/**
	 * 报表数据来源：0:中间表、1:sql语句、2:接口
	 */
	@Column
	protected int source;

	/**
	 * 最大行数，0表示不限制
	 */
	@Column
	@Validations(rules = {
		@ValidateType(type=ValidateRuleType.required, msgkey="report.validate.limit.required", bundle="report"),
		@ValidateType(type=ValidateRuleType.digits, msgkey="report.validate.limit.illegal", bundle="report")
	})
	protected int limit;

	/**
	 * 报表文件生存时间:单位天
	 */
	@Column
	@Validations(rules = {
		@ValidateType(type=ValidateRuleType.required, msgkey="report.validate.lifetime.required", bundle="report"),
		@ValidateType(type=ValidateRuleType.range, parameters={"1", "365"}, msgkey="report.validate.lifetime.illegal", bundle="report")
	})
	protected int lifetime = 30;

	/**
	 * 是否显示列标题
	 */
	@Column
	protected boolean showColumnTitle = true;
	
	/**
	 * 是否为预定义（内置）报表，只读
	 */
	@Column
	protected boolean system;

	/**
	 * 报表统计条件
	 * 暂时用作查看报表条件的参数
	 */
	@Column
	protected String strategy;

	/**
	 * 页眉页脚信息
	 */
	protected ReportPage page = new ReportPage();

	/**
	 * 报表数据提供者
	 */
	protected ReportQuery query;
	
	/**
	 * 报表统计图
	 *  支持多个统计图
	 */
	protected List<ReportChart> charts;
	
	public ReportObject() {

	}

	public String getCacheid() {
		return cacheid;
	}

	public void setCacheid(String cacheid) {
		this.cacheid = cacheid;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubtitle() {
		return subtitle;
	}

	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	public int getSource() {
		return source;
	}

	public void setSource(int source) {
		this.source = source;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public boolean isShowColumnTitle() {
		return showColumnTitle;
	}

	public void setShowColumnTitle(boolean showColumnTitle) {
		this.showColumnTitle = showColumnTitle;
	}

	public boolean isSystem() {
		return system;
	}

	public void setSystem(boolean system) {
		this.system = system;
	}

	public int getLifetime() {
		return lifetime;
	}

	public void setLifetime(int lifetime) {
		this.lifetime = lifetime;
	}

	public String getStrategy() {
		return strategy;
	}

	public void setStrategy(String strategy) {
		this.strategy = strategy;
	}

	public ReportPage getPage() {
		return page;
	}

	public void setPage(ReportPage page) {
		this.page = page;
	}

	public ReportQuery getQuery() {
		return query;
	}

	public void setQuery(ReportQuery query) {
		this.query = query;
	}

	public List<ReportChart> getCharts() {
		return charts;
	}

	public void setCharts(List<ReportChart> charts) {
		this.charts = charts;
	}

	public void addChart(ReportChart chart) {
		if (this.charts == null)
			this.charts = new ArrayList<ReportChart>();
		this.charts.add(chart);
	}
	
}
